package engine;

import javax.media.Player;

import engine.events.HINBEventListener;
import engine.motionDetection.EngineMotionDetectionInterface;

public class HINBsEngineThread extends Thread{
	/* *********************************************************
	 * Attributes
	 * ********************************************************* */
	private static HINBsEngineThread instance = new HINBsEngineThread();
	//private engine stuff 
	private boolean _running;
	
	/* *********************************************************
	 * Constructor(s)
	 * ********************************************************* */
	/**
	 * Default constructor
	 * Note : it calls the startMethod when it's done
	 */
	private HINBsEngineThread(){
		super();
		System.out.println("engine : HINBsEngineThread");
		//init the engine stuff ...
		
		this._running = true;
		this.start();
	}
	
	/* *********************************************************
	 * Instance Methods
	 * ********************************************************* */
	@Override
	public void run() {
		super.run();
		System.out.println("engine : run");
		while(_running){
			//nothing to do for now...
		}
		System.out.println("engine turning off");
	}
	/**
	 * Method called to stop the HINBsUserInterfaceThread :
	 * ask the thread to stop as soon as possible.
	 */
	public void stopASAP(){
		System.out.println("engine : stopASAP");
		this._running = false;
	}
	public EngineMotionDetectionInterface createAndLauchMotionDetection(Player webCamplayer,HINBEventListener listener){
		System.out.println("engine : createAndLauchMotionDetection");
		EngineMotionDetectionInterface motionThread = 
			new EngineMotionDetectionInterface(webCamplayer);
		motionThread.addEventListener(listener);
		return motionThread;
	}
	/* *********************************************************
	 * Static Methods
	 * ********************************************************* */
	public static HINBsEngineThread getInstance(){
		System.out.println("engine : getInstance");
		return instance;
	}
}
